package com.bookmanager.www.mapper;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bookmanager.www.common.DTO.AdvancedSearchOrdersDTO;
import com.bookmanager.www.common.PO.CountAndPricePO;
import com.bookmanager.www.entity.FlBookOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bookmanager.www.entity.FlBookTemp;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 图书订单 Mapper 接口
 * </p>
 *
 * @author 风离
 * @since 2021-09-17
 */
public interface FlBookorderMapper extends BaseMapper<FlBookOrder> {

    /**
     * 创建用户订单
     * @param orderId
     * @param userId
     * @param status
     * @param payment
     * @param paymentType
     * @param freight
     * @param addressId
     * @param createdDate
     * @param updateDate
     * @return
     */
    Integer createOrder(@Param("order_id") String orderId, @Param("user_id") String userId,
                        @Param("status") Integer status, @Param("payment") BigDecimal payment,
                        @Param("payment_type") Integer paymentType, @Param("freight") Integer freight,
                        @Param("address_id")String addressId, @Param("create_time") LocalDateTime createdDate, @Param("update_time") LocalDateTime updateDate);

    /**
     * 根据订单ID查找订单
     * @param orderId
     * @return
     */
    FlBookOrder selectOrderByOrderId(@Param("order_id") String orderId);

    /**
     * 根据订单id 修改订单支付状态
     * @param orderId
     * @param i
     * @return
     */
    int changeStatusByOrderId(@Param("order_id")String orderId, @Param("status")int i);


    /**
     * 根据用户id查询订单信息
     * @param userId
     * @return
     */
    List<FlBookOrder> selectOrderByUserId(@Param("user_id") String userId);



    /**
     * 根据TempId查找订单分支
     * @param tempId
     * @return
     */
    FlBookTemp selectOrderTempByTempId(@Param("temp_id")String tempId);


    List<FlBookTemp> selectOrderTempByOrderId(@Param("order_id")String orderId);

    /**
     *  111
     * @param tempId
     * @param orderId
     * @param bookId
     * @param count
     * @return
     */
    int createOrderTemp(@Param("tempId")String tempId,@Param("orderId") String orderId,
                        @Param("bookId") String bookId,@Param("count") Integer count);

    /**
     * 分页查询图书订单情况
     * @param p
     * @param flBookOrder
     * @param status
     * @param flag
     * @param userId
     * @return
     */
    List<FlBookOrder> selectBookOrderPageExt(Page<FlBookOrder> p, FlBookOrder flBookOrder,@Param("userId")String userId,
                                             @Param("status") int status,@Param("addressId") String flag);

    /**
     * 分页查询余额订单情况
     * @param p
     * @param flBookOrder
     * @param status
     * @param flag
     * @param userId
     * @return
     */
    List<FlBookOrder> selectAccountOrderPageExt(Page<FlBookOrder> p, FlBookOrder flBookOrder,@Param("userId")String userId,
                                                @Param("status") int status,@Param("addressId") String flag);

    /**
     * 更新订单支付时间
     * @param orderId
     * @param now
     * @return
     */
    int updatePaymentTime(@Param("orderId")String orderId,@Param("paymentTime") LocalDateTime now);


    /**
     * 根据订单修改支付类型
     * @param orderId
     * @param i
     * @return
     */
    int updatePaymentTypeByOrderId(@Param("orderId")String orderId,@Param("paymentType") int i);

    /**
     * 查询某用户所有订单（分页查询）
     * @param p
     * @param flBookOrder
     * @param userId
     * @return
     */
    List<FlBookOrder> selectAllBookOrderPageExt(Page<FlBookOrder> p, FlBookOrder flBookOrder,@Param("userId") String userId);

    /**
     * 查询所有余额订单分页不分状态
     * @param p
     * @param flBookOrder
     * @param userId
     * @param flag
     * @return
     */
    List<FlBookOrder> selectAccountOrderPageExtAll(Page<FlBookOrder> p, FlBookOrder flBookOrder,@Param("userId") String userId, @Param("addressId")String flag);

    /**
     * 查询所有人图书订单（分页查询）
     * @param p
     * @param flBookOrder
     * @param flag
     * @return
     */
    List<FlBookOrder> selectAllBookOrder(Page<FlBookOrder> p, FlBookOrder flBookOrder,@Param("addressId") String flag);

    /**
     * 查询所有人余额订单
     * @param p
     * @param flBookOrder
     * @param flag
     * @return
     */
    List<FlBookOrder> selectAllAccountOrder(Page<FlBookOrder> p, FlBookOrder flBookOrder,@Param("addressId") String flag);

    /**
     * 统计订单
     * @param startDate
     * @param endDate
     * @return
     */
    List<FlBookOrder> selectOrdersByTime(@Param("startTime") DateTime startDate,@Param("endTime") DateTime endDate);

    /**
     * 获取当月订单金额和价值
     * @param startTime
     * @param thisMonth
     * @return
     */
    CountAndPricePO getAllCountAndAllPriceByTime(@Param("startTime") String startTime,
                                                 @Param("endTime") String thisMonth);

    /**
     * 批量删除订单
     * @param orderId
     * @return
     */
    int deleteOrderByOrderId(@Param("orderId")String orderId);

    /**
     * 根据订单id获取订单状态
     * @param orderId
     * @return
     */
    Integer getStatusByOrderId(@Param("orderId")String orderId);

    /**
     * 订单高级搜索
     * @param p
     * @param a
     * @return
     */
    List<FlBookOrder> advancedSearchOrders(Page<FlBookOrder> p,
                                           @Param("a")
                                           AdvancedSearchOrdersDTO a);

    /**
     * 优化订单时间 防止重复查询数据库
     * @param orderIdList
     * @return
     */
    List<FlBookTemp> selectOrderTempByOrderIdList(@Param("o") ArrayList orderIdList);
}
